/*
 * @Author: qianmingtian
 * @Date: 2020-07-08 09:13:28
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-07-08 11:57:22
 * @FilePath: \qianmingtian.github.io\code\java\abstractPrac\EqualTest.java
 */
package abstractPrac;

import java.security.KeyStore.ProtectionParameter;

import javafx.scene.transform.Affine;
import sun.rmi.runtime.NewThreadAction;

class User implements Cloneable {
    String name;
    Address addr;

    public User(String name, Address addr) {
        this.name = name;
        this.addr = addr;
    }

    public boolean equals(Object o) {
        if (o == null || !(o instanceof User))
            return false;

        if (this == o)
            return true;

        User u = (User) o;
        if (this.name.equals(u.name) && this.addr.equals(u.addr)) {
            return true;
        }

        return false;

    }

    protected void finalize() throws Throwable {
        System.out.println("即将被销毁");
    }

    @Override
    protected Object clone() throws CloneNotSupportedException{
        return super.clone();
    }
}

class Address {
    String city;
    String no;

    Address() {

    }

    Address(String city, String no) {
        this.city = city;
        this.no = no;
    }

    public String toString() {
        return city + no;
    }

    public boolean equals(Object obj) {

        if (obj == null || !(obj instanceof Address))
            return false;

        if (this == obj)
            return true;

        Address addr = (Address) obj;
        if (this.city.equals(addr.city) && this.no.equals(addr.no))
            return true;

        return false;

    }

}

public class EqualTest {
    public static void main(String[] args) {
        User u1 = new User("张胆", new Address("huaxia", "123"));
        User u2 = new User("张胆", new Address("huaxia", "123"));
        // for (int i = 0; i < 100; i++) {

        //     Address add = new Address();
        //     add = null;

        //     System.gc();
        // }

        Object u3 = new User("", new Address("huaxia", "123"));
        Object u4 = new User("张胆", new Address("huaxia", "123"));

        System.out.println(u3.equals(u4));

        Object u5 = new Address();


        
        Object u6 = new Address();
        int u = u5.hashCode();
        System.out.println(u);
    }

}/*
  * @Author: qianmingtian
  * 
  * @Date: 2020-07-08 09:13:28
  * 
  * @LastEditors: qianmingtian
  * 
  * @LastEditTime: 2020-07-08 09:13:28
  * 
  * @FilePath: \qianmingtian.github.io\code\java\abstractPrac\EqualTest.java
  */
